home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / mfbtegblt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-15  |  8.8 KB  |  320 lines

  1. /* $XConsortium: mfbtegblt.c,v 5.5 89/11/21 15:19:41 keith Exp $ */
  2. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  3. /***********************************************************
  4. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  5. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its 
  10. documentation for any purpose and without fee is hereby granted, 
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in 
  13. supporting documentation, and that the names of Digital or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.  
  16.  
  17. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26. #include    "X.h"
  27. #include    "Xmd.h"
  28. #include    "Xproto.h"
  29. #include    "fontstruct.h"
  30. #include    "dixfontstr.h"
  31. #include    "gcstruct.h"
  32. #include    "windowstr.h"
  33. #include    "scrnintstr.h"
  34. #include    "pixmapstr.h"
  35. #include    "regionstr.h"
  36. #include    "mfb.h"
  37. #include    "maskbits.h"
  38.  
  39. /*
  40.     this works for fonts with glyphs <= 32 bits wide.
  41.  
  42.     This should be called only with a terminal-emulator font;
  43. this means that the FIXED_METRICS flag is set, and that
  44. glyphbounds == charbounds.
  45.  
  46.     in theory, this goes faster; even if it doesn't, it reduces the
  47. flicker caused by writing a string over itself with image text (since
  48. the background gets repainted per character instead of per string.)
  49. this seems to be important for some converted X10 applications.
  50.  
  51.     Image text looks at the bits in the glyph and the fg and bg in the
  52. GC.  it paints a rectangle, as defined in the protocol dcoument,
  53. and the paints the characters.
  54.  
  55.    to avoid source proliferation, this file is compiled
  56. two times:
  57.     MFBTEGLYPHBLT        OP
  58.     mfbTEGlyphBltWhite        (white text, black bg )
  59.     mfbTEGlyphBltBlack    ~    (black text, white bg )
  60.  
  61. */
  62.  
  63. #if defined(NO_3_60_CG4) && defined(FASTPUTBITS) && defined(FASTGETBITS)
  64. #define FASTCHARS
  65. #endif
  66.  
  67. /*
  68.  * this macro "knows" that only characters <= 8 bits wide will
  69.  * fit this case (which is why it is independent of GLYPHPADBYTES)
  70.  */
  71.  
  72. #if (BITMAP_BIT_ORDER == MSBFirst) && (GLYPHPADBYTES != 4)
  73. #if GLYPHPADBYTES == 1
  74. #define ShiftAmnt   24
  75. #else
  76. #define ShiftAmnt   16
  77. #endif
  78.  
  79. #define GetBits4    c = (*char1++ << ShiftAmnt) | \
  80.             SCRRIGHT (*char2++ << ShiftAmnt, xoff2) | \
  81.             SCRRIGHT (*char3++ << ShiftAmnt, xoff3) | \
  82.             SCRRIGHT (*char4++ << ShiftAmnt, xoff4);
  83. #else
  84. #define GetBits4    c = *char1++ | \
  85.             SCRRIGHT (*char2++, xoff2) | \
  86.             SCRRIGHT (*char3++, xoff3) | \
  87.             SCRRIGHT (*char4++, xoff4);
  88. #endif
  89.  
  90.  
  91. #if GLYPHPADBYTES == 1
  92. typedef    unsigned char    *glyphPointer;
  93. #define USE_LEFTBITS
  94. #endif
  95.  
  96. #if GLYPHPADBYTES == 2
  97. typedef unsigned short    *glyphPointer;
  98. #define USE_LEFTBITS
  99. #endif
  100.  
  101. #if GLYPHPADBYTES == 4
  102. typedef unsigned int    *glyphPointer;
  103. #endif
  104.  
  105. #ifdef USE_LEFTBITS
  106. #define GetBits1    getleftbits (char1, widthGlyph, c); \
  107.             c &= glyphMask; \
  108.             char1 = (glyphPointer) (((char *) char1) + glyphBytes);
  109. #else
  110. #define GetBits1    c = *char1++;
  111. #endif
  112.  
  113. void
  114. MFBTEGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  115.     DrawablePtr pDrawable;
  116.     GC         *pGC;
  117.     int     x, y;
  118.     unsigned int nglyph;
  119.     CharInfoPtr *ppci;        /* array of character info */
  120.     unsigned char *pglyphBase;    /* start of array of glyphs */
  121. {
  122.     CharInfoPtr pci;
  123.     FontInfoPtr pfi = pGC->font->pFI;
  124.     int widthDst;
  125.     unsigned int *pdstBase;    /* pointer to longword with top row 
  126.                    of current glyph */
  127.  
  128.     int h;            /* height of glyph and char */
  129.     register int xpos;        /* current x  */
  130.     int ypos;            /* current y */
  131.     int widthGlyph;
  132.  
  133.     int hTmp;            /* counter for height */
  134.     register int startmask, endmask;
  135.     int nfirst;            /* used if glyphs spans a longword boundary */
  136.     BoxRec bbox;        /* for clipping */
  137.     int    widthGlyphs;
  138.     register unsigned int  *dst;
  139.     register unsigned int  c;
  140.     register int        xoff1, xoff2, xoff3, xoff4;
  141.     register glyphPointer   char1, char2, char3, char4;
  142.  
  143. #ifdef USE_LEFTBITS
  144.     register int        glyphMask;
  145.     register unsigned int  tmpSrc;
  146.     register int        glyphBytes;
  147. #endif
  148.  
  149.     if (pDrawable->type == DRAWABLE_WINDOW)
  150.     {
  151.     pdstBase = (unsigned int *)
  152.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  153.     widthDst = (int)
  154.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  155.     }
  156.     else
  157.     {
  158.     pdstBase = (unsigned int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  159.     widthDst = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  160.     }
  161.  
  162.     xpos = x + pDrawable->x;
  163.     ypos = y + pDrawable->y;
  164.  
  165.     pci = &pfi->maxbounds;
  166.     widthGlyph = pci->metrics.characterWidth;
  167.     h = pfi->fontAscent + pfi->fontDescent;
  168.  
  169.     xpos += pci->metrics.leftSideBearing;
  170.     ypos -= pfi->fontAscent;
  171.  
  172.     bbox.x1 = xpos;
  173.     bbox.x2 = xpos + (widthGlyph * nglyph);
  174.     bbox.y1 = ypos;
  175.     bbox.y2 = ypos + h;
  176.  
  177.     switch ((*pGC->pScreen->RectIn)(
  178.                 ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
  179.     {
  180.       case rgnPART:
  181.     /* this is the WRONG thing to do, but it works.
  182.        calling the non-terminal text is easy, but slow, given
  183.        what we know about the font.
  184.  
  185.        the right thing to do is something like:
  186.         for each clip rectangle
  187.         compute at which row the glyph starts to be in it,
  188.            and at which row the glyph ceases to be in it
  189.         compute which is the first glyph inside the left
  190.             edge, and the last one inside the right edge
  191.         draw a fractional first glyph, using only
  192.             the rows we know are in
  193.         draw all the whole glyphs, using the appropriate rows
  194.         draw any pieces of the last glyph, using the right rows
  195.  
  196.        this way, the code would take advantage of knowing that
  197.        all glyphs are the same height and don't overlap.
  198.  
  199.        one day...
  200.     */
  201.     CLIPTETEXT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
  202.       case rgnOUT:
  203.     return;
  204.     }
  205.     pdstBase += widthDst * ypos;
  206.     widthGlyphs = widthGlyph << 2;
  207.  
  208. #ifdef USE_LEFTBITS
  209.     glyphMask = endtab[widthGlyph];
  210.     glyphBytes = GLYPHWIDTHBYTESPADDED(pci);
  211. #endif
  212.  
  213.     if (nglyph >= 4 && widthGlyphs <= 32)
  214.     {
  215.     while (nglyph >= 4)
  216.     {
  217.         nglyph -= 4;
  218.         xoff1 = xpos & 0x1f;
  219.         xoff2 = widthGlyph;
  220.         xoff3 = xoff2 + widthGlyph;
  221.         xoff4 = xoff3 + widthGlyph;
  222.         char1 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  223.         char2 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  224.         char3 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  225.         char4 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  226.  
  227.         hTmp = h;
  228.         dst = pdstBase + (xpos >> 5);
  229.  
  230. #ifndef FASTCHARS
  231.         if (xoff1 + widthGlyphs <= 32)
  232.         {
  233.         maskpartialbits (xoff1, widthGlyphs, startmask);
  234. #endif
  235.         while (hTmp--)
  236.         {
  237.             GetBits4
  238. #ifdef FASTCHARS
  239. # if BITMAP_BIT_ORDER == MSBFirst
  240.             c >>= 32 - widthGlyphs;
  241. # endif
  242.             FASTPUTBITS(OP(c), xoff1, widthGlyphs, dst);
  243. #else
  244.             *(dst) = (*dst) & ~startmask | OP(SCRRIGHT(c, xoff1)) & startmask;
  245. #endif
  246.             dst += widthDst;
  247.         }
  248. #ifndef FASTCHARS
  249.         }
  250.         else
  251.         {
  252.         mask32bits (xoff1, widthGlyphs, startmask, endmask);
  253.         nfirst = 32 - xoff1;
  254.         while (hTmp--)
  255.         {
  256.             GetBits4
  257.             dst[0] = dst[0] & ~startmask |
  258.                  OP(SCRRIGHT(c,xoff1)) & startmask;
  259.             dst[1] = dst[1] & ~endmask |
  260.                  OP(SCRLEFT(c,nfirst)) & endmask;
  261.             dst += widthDst;
  262.         }
  263.         }
  264. #endif
  265.         xpos += widthGlyphs;
  266.     }
  267.     }
  268.  
  269.     while(nglyph--)
  270.     {
  271.     xoff1 = xpos & 0x1f;
  272.     char1 = (glyphPointer) (pglyphBase + (*ppci++)->byteOffset);
  273.     hTmp = h;
  274.     dst = pdstBase + (xpos >> 5);
  275.  
  276. #ifndef FASTCHARS
  277.     if (xoff1 + widthGlyph <= 32)
  278.     {
  279.         maskpartialbits (xoff1, widthGlyph, startmask);
  280. #endif
  281.         while (hTmp--)
  282.         {
  283. #ifdef FASTCHARS
  284. #ifdef USE_LEFTBITS
  285.         FASTGETBITS (char1,0,widthGlyph,c);
  286.         char1 = (glyphPointer) (((char *) char1) + glyphBytes);
  287. #else
  288.         c = *char1++;
  289. #if BITMAP_BIT_ORDER == MSBFirst
  290.         c >>= 32 - widthGlyph;
  291. #endif
  292. #endif
  293.         FASTPUTBITS (OP(c),xoff1,widthGlyph,dst);
  294. #else
  295.         GetBits1
  296.         (*dst) = (*dst) & ~startmask | OP(SCRRIGHT(c, xoff1)) & startmask;
  297. #endif
  298.         dst += widthDst;
  299.         }
  300. #ifndef FASTCHARS
  301.     }
  302.     else
  303.     {
  304.         mask32bits (xoff1, widthGlyph, startmask, endmask);
  305.         nfirst = 32 - xoff1;
  306.         while (hTmp--)
  307.         {
  308.         GetBits1
  309.         dst[0] = dst[0] & ~startmask |
  310.              OP(SCRRIGHT(c,xoff1)) & startmask;
  311.         dst[1] = dst[1] & ~endmask |
  312.              OP(SCRLEFT(c,nfirst)) & endmask;
  313.         dst += widthDst;
  314.         }
  315.     }
  316. #endif
  317.     xpos += widthGlyph;
  318.     }
  319. }
  320.